import 'package:flutter/material.dart';
import 'package:poet/pages/CollectionPage.dart';
import 'package:poet/pages/recommend_page/index.dart';
import 'package:poet/pages/search_page/index.dart';
import 'package:poet/pages/theme_config.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '晓诗',
      home: HomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class HomePage extends StatefulWidget {
  HomePage({Key key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with SingleTickerProviderStateMixin {
  int _currentIndex = 0;
  List<Widget> _list = List();

  void _onItemTapped(int index) {
    setState(() {
      _currentIndex = index;
    });
  }

  @override
  void initState() {
    super.initState();
    _list..add(RecommendPage())..add(SearchPage())..add(CollectionPage());
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: new MAppBar(),
        body: IndexedStack(
          index: _currentIndex,
          children: _list,
        ),
        bottomNavigationBar: BottomNavigationBar(
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('荐')),
            BottomNavigationBarItem(icon: Icon(Icons.search), title: Text('寻')),
            BottomNavigationBarItem(
                icon: Icon(Icons.bookmark), title: Text('藏')),
          ],
          currentIndex: _currentIndex,
          type: BottomNavigationBarType.fixed,
          onTap: _onItemTapped,
        ));
  }
}

class MAppBar extends StatefulWidget implements PreferredSizeWidget {
  @override
  Size get preferredSize {
    return new Size.fromHeight(56.0);
  }

  @override
  State createState() {
    return new MAppBarState();
  }
}

class MAppBarState extends State<MAppBar> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Theme.of(context).primaryColor,
      child: SafeArea(
        child: Container(
          height: 0,
        ),
        top: true,
      ),
    );
  }
}
